import Vue from 'vue';
const config = Vue.config.devtools ?
    {
        // api_url: "//" + window.location.host + "/rest/"
        api_base_url: "//localhost/",
        api_url: "//localhost/rest/"
    } : {
        // api_url: "//" + window.location.host + "/rest/"
        api_base_url: `${location.protocol}//${location.host}/`,
        api_url: `${location.protocol}//${location.host}/rest/`,
    };
export default config;
export const fetchRest = (url, ...args) => {
    return fetch(config.api_url + url, ...args)
        .then(response => response.json())
        .then(json => {
            if (json.status === "success") {
                return json.data
            } else if (json.status === "error") {
                throw json.error
            } else {
                throw json
            }
        });
}
export const getCategoryUrl = (category) => {
    if (category.model === "article") {
        return '/article-list/' + category.dir
    } else if (category.model === "page") {
        return '/single-page/' + category.dir
    } else if (category.model === "product" && category.dir === "doctors") {
        return '/doctors'
    } else {
        return '/404';
    }
}